﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Work
{
    class Program
    {
        static void Main(string[] args)
        {
            func a = new func();
            double b = a.fun1();
            Console.WriteLine($"方法一结果为：{b}");
            b = a.fun2();
            Console.WriteLine($"方法二结果为：{b}");
            b = a.fun3();
            Console.WriteLine($"方法三结果为：{b}");
            /*注意！两个整形相除即使是强制类型转换还是整形，比如 g= (double)(1/2); g的结果是0;
             * int c = 1,f=2;
            float d = 2;
            double e = 1.0;
            d = c + d;
            e = e + c;
            double g= (double)(1/2);
            Console.WriteLine($"{d}   {g}");*/
            Console.ReadKey();
        }
    }
    class func
    {
        public double fun1()//方法一，使用while;
        {
            double sum=1.0;
            double i = 1;
            while (i < 100)
            {
                sum+=(i / (i + 1));
                i++;
            }
            return sum;
            
        }
        public double fun2()//方法二，使用do while;
        {
            double sum = 1.0;
            double i = 1;
            do
            {
                sum += (i / (i + 1));
                i++;
            }
            while (i < 100);
            return sum;

        }
        public double fun3()//方法三，使用for语句;
        {
            double sum = 1.0;
            for (double i = 1; i < 100; i++)
            {
                sum += i / (i + 1);
            }
            return sum;

        }

    }
}
